<?php
if($action=="view" && $id>0){
//----------------------------------------->查看<-------------------------------------------------
	$tpl->assign("page_title","车辆信息查看");//title
	$sa=$db->query_first("select * from n_car where id=$id limit 1");
	$sa[license]=($_SESSION[member]>0 and $_SESSION[login]=='yes')?make_license($sa):'！只有牛行网会员才可查看 <i><a href=member/login.php target=$_blank>登陆</a> <a href=member/reg.php target=_blank>注册</a></i>';
	$owner=$db->query_first("select * from n_member where id=$sa[owner]");
	$owner=get_row("n_".$owner[extent],$owner[id_owner],"name");
	$sa[name_owner]=$owner;
	$sa[rate]=getMemberRateImg($sa[owner]);
	$sa[name_driver]=$sa[driver]>0?get_row("n_driver",$sa[driver],"name"):"无";
	$sa[style]=$car_style[$sa[style]];
	$sa[length]=$car_length[$sa[length]];
	$sa[color]=$car_color[$sa[color]];
	$sa[status]=($sa[status]=="busy" or $sa[status]=="trans")?"繁忙":"空闲";
	if ($sa[id_line]>0){
		$line=$db->query_first("select * from n_line where id='$sa[id_line]' limit 1");
		$sa[line]=read_line($line);
	}else{
		$area="";
		$areas=explode(",",$sa[area]);
		foreach($areas as $key=>$area_id){
			$area.=get_place_name($area_id)." ";
		}
		$sa[area]=$area;
	}
	if ($sa[province]>0){
		$sa[position]=get_place_name($sa[province]);
		if ($sa[city]>0){
			$sa[position].=" ".get_place_name($sa[city]);
			if ($sa[county]>0){
				$sa[position].=" ".get_place_name($sa[county]);
			}
		}
	}
	$sb=$db->query("select * from n_photo where kind='car' and id_kind='$id' order by id desc limit 1");
	if ($db->num_rows($sb)==1){
		$sb=$db->fetch_array($sb);
		$sa[photo]=NXHOST.$sb[url]."thumb/thumb_".$sb['file'];
	}else{
		$sa[photo]=NXHOST.'images/'.$_NCACHE['sets']['useskin'].'/empty.jpg';
	}
	$sa[t_add]=date("Y-m-d H:i:s");
	$tpl->assign("car",$sa);
}elseif ($action=='photo'){
	$page_title='查看车辆照片';
	$sa=$db->query_first("select * from n_car where id=$id limit 1");
	$sa[license]=make_license($sa);
	$tpl->assign("car",$sa);
	unset($sa);
	$sa=$db->query("select * from n_photo where `kind`='car' and `id_kind`='$id' order by id desc");
	while ($sb=$db->fetch_array($sa)){
		$img=NXHOST.$sb[url].'thumb/thumb_'.$sb['file'];
		//if (file_exists($img)){
			$array[]=array('id'=>$sb[id],'img'=>$img);
		//}
	}
	$tpl->assign('photo_num',$photo_num);
	$tpl->assign('photo',$array);
	$photo_num=$db->num_rows($sa);
	if ($photo_num % 4 !=0){
		$num=4-($photo_num % 4);
		for($i=0;$i<$num;$i++){
			$tds.="<td></td>";
		}
		$tpl->assign('tds',$tds);
	}
}else{
//----------------------------------------->列表<-------------------------------------------------
	$tpl->assign("page_title","网络车场");//title
	$sa=$db->query("select * from n_car order by id limit 50");
	while($sb=$db->fetch_array($sa)){
			if ($sb[id_line]>0){//专线
				$line=$db->query_first("select * from n_line where id=$sb[id_line]");
				$area=read_line($line);
			}else{//常去城市
				$areas=explode(",",$sb[area]);
				$area="";
				foreach($areas as $key=>$value){
					!empty($value) && $area.=get_place_name($value)." ";
				}
			}
		$array[]=array(
						//"license"=>make_license($sb),
						"license"=>$sb[id],
						"area"=>cutstr($area,56),
						"splace"=>$splace,
						"eplace"=>$eplace,
						"carry"=>($sb[carry]==2)?"重货":"轻货",
						"style"=>$car_style[$sb[style]],
						"weight"=>round($sb[weight],3)." 吨",
						"volume"=>round($sb[volume],3)." 方",
						"status"=>($sb[status]=='busy' or $sb[status]=='trans')?'繁忙':'空闲',
						"id"=>$sb[id],
				);
	}
	$tpl->assign("list_car",$array);
	unset($array);
}
?>